package com.sy.department.web.impl;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sy.department.dao.po.DepartmentPo;
import com.sy.department.service.IDepartmentService;
import com.sy.department.utils.ResultUtils;
import com.sy.department.utils.ResultVo;
import com.sy.department.web.IDepartmentController;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 部门信息表 前端控制器
 * </p>
 *
 * @author Administrator
 * @since 2025-04-08
 */
@RestController
@RequestMapping("/department")
public class DepartmentController implements IDepartmentController {

    @Resource
    private IDepartmentService service;

    @PostMapping("/get")
    public RespGetDepartment getDepartment(ReqQueryDepartment args) {
        DepartmentPo po = service.getById(args.getId());
        return new RespGetDepartment(po);
    }

    @GetMapping("/list")
    public RespListDepartment listDepartment(ReqQueryDepartment fo) {
        List<DepartmentPo> pos = service.listDepartment(fo);
        return new RespListDepartment(pos);
    }

    @GetMapping("/page")
    public RespPageDepartment pageDepartment(ReqQueryDepartment fo) {
        Page<DepartmentPo> poPage = service.pageDepartment(fo);
        return new RespPageDepartment(poPage);
    }

    @PostMapping("/put")
    public RespAddDepartment addDepartment(@RequestBody DepartmentPo po) {
        System.out.println(po);
        service.save(po);
        return new RespAddDepartment();
    }

    @PostMapping("/post")
    public RespUpdateDepartment updateDepartment(@RequestBody DepartmentPo po) {
        service.updateById(po);
        return new RespUpdateDepartment();
    }

    @PostMapping("/delete")
    public RespDeleteDepartment deleteDepartment(@RequestBody DepartmentPo po) {
        service.removeById(po.getId());
        return new RespDeleteDepartment();
    }

}

